using System;
using kerberosLibs;

namespace UpdateKerberosConfig
{
	/// <summary>
	/// Dirt simple application that will update the
    /// krb5 file if required.
	/// </summary>
	class MainCode
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			////
			/// We shouldn't run if there is no installed produce...
			/// 

			if (kerberosProductAccess.isInstalled) 
			{
				try 
				{
					AutoUpdate up = new AutoUpdate();
					up.KRBTemplateLocation = kerberosProductAccess.TemplatePath;
					up.KRBLocation = kerberosProductAccess.KRBConfPath;
					up.UpdateIf ();
				} 
				catch (Exception e) 
				{
					System.Text.StringBuilder b = new System.Text.StringBuilder ();
					b.Append ("Unexpected Error Updating the Kerberos Config File: " + e.Message + "\n");
					b.Append ("Stack Trace " + e.StackTrace);
					Console.WriteLine (b.ToString());

					System.Diagnostics.EventLog l = new System.Diagnostics.EventLog ("Application", ".", "Kerberos Configure Standalone Updater");
					l.WriteEntry (b.ToString(), System.Diagnostics.EventLogEntryType.Error, 0, 0);
				}
			}
		}
	}
}
